﻿using CommonTools;
using shop.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace shop.Bll.BasicInfo
{
    /// <summary> 开票单位 基础资料 </summary>
    public class JTaxCompanyBll : IFastQueryBll<JTaxCompany>
    {

        private List<object> _items;


        #region 实现IFastQueryBll 接口, 在FastBox中使用



        /// <summary> 在查询窗体,报表中显式的名称 </summary>
        public string Title => "开票单位";


        /// <summary> 本地存储的明细 </summary>
        /// <remarks>如果基础资每次都从数据库查询, 这个没用, 保持null</remarks>
        public List<JTaxCompany> Items => null;


        /// <summary> 是否每次从数据库查询 </summary>
        public bool QueryFromDataBase => true;



        /// <summary> 显示的列, 静态 </summary>
        private static readonly string[] _columns = new string[] { nameof(JTaxCompany.Name) };


        /// <summary> 存储在快速查询窗体中,显示的属性 </summary>
        public string[] Columns => _columns;


        /// <summary> 实体模型的代码属性名称 </summary>
        public string CodeField => nameof(JTaxCompany.Code);

        public string Separator => string.Empty;

        public Dictionary<string, string> DisplayColumns { set; get; } = new Dictionary<string, string>() { { "Name", "名称" } };






        /// <summary> 查询方法 </summary>
        public List<JTaxCompany> Query(string findText, string prefixCode = null)
        {
            //var sql1_ = DB.FSql.Select<SalesAmount>()
            //    .Where(a => a.Isdel == false && string.IsNullOrEmpty(a.Company) == false);
            ////var sql2_ = DB.FSql.Select<SalesPay>()
            ////.Where(a => a.Isdel == false && string.IsNullOrEmpty(a.Company) == false);
            ////var sql3_ = DB.FSql.Select<PrdtPay>()
            //var sql3_ = DB.FSql.Select<PrdtPayRecord, PrdtPayRecordItem>()
            //    .InnerJoin((a,b )=> a.DocId == b.DocId)
            //    .Where((a,b) => a.Isdel == false && b.Isdel == false 
            //        && string.IsNullOrEmpty(b.Company ) == false);

            //if (string.IsNullOrEmpty(findText) == false)
            //{
            //    sql1_ = sql1_.Where(a => a.Company.Contains(findText));
            //    //sql2_ = sql2_.Where(a => a.Company.Contains(findText));
            //    sql3_ = sql3_.Where((a,b) => b.Company.Contains(findText));
            //}
            //var sql1 = sql1_.ToSql("Company");
            ////var sql2 = sql2_.ToSql("Company");
            //var sql3 = sql3_.ToSql("Company");

            //var list = DB.FSql.Select<object>()
            //    .WithSql(sql1)
            //    .WithSql(sql3)
            //    .Distinct()
            //    .Take(100)
            //    .ToList<JTaxCompany>("Company as Name");

            //return list;
            return null;
        }


        /// <summary> 查询树形图的一个节点下的所有内容 </summary>
        public List<JTaxCompany> QueryByGroup(string group)
        {
            return Query(null, null);
        }

        public IEnumerable<IFastTree> QueryTreeList()
        {
            return new[] { new JTaxCompany() { Name = "", } };
        }


        #endregion




    }

}
